home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / Pascal OS8 / AMReminder / MainWindow.p < prev    next >
Encoding:
Text File  |  1998-10-30  |  8.8 KB  |  477 lines  |  [TEXT/CWIE]

  1. { MainWindow.p }
  2. { Created 10/30/98 1:03 PM by AppMaker }
  3.  
  4. Unit MainWindow;
  5. Interface
  6.  
  7. Uses
  8.     Types,
  9.     Quickdraw,
  10.     Controls,
  11.     Dialogs,
  12.     Events,
  13.     Lists,
  14.     Menus,
  15.     Resources,
  16.     TextEdit,
  17.     ToolUtils,
  18.  
  19.     Add,
  20.     DDocData,
  21.     AMReminderEngine,
  22.     AMReminderDoc,
  23.     AMWindow;
  24.  
  25. type
  26.     MainWindow        = object (AMWindow)
  27.  
  28.     {data members}
  29.         mData:            DDocData;
  30.         mLogoHandle:        ControlHandle;
  31.         mYearLabel:    ControlHandle;
  32.         mRemindersLabelLabel:    ControlHandle;
  33.         mRemindersHandle:        ControlHandle;
  34.         mAddHandle:        ControlHandle;
  35.         mEditHandle:        ControlHandle;
  36.         mDeleteHandle:        ControlHandle;
  37.  
  38.     {methods}
  39.         Procedure Initialize; Override;
  40.  
  41.         Procedure Open        (inDoc:        AMReminderDoc;
  42.                              inData:    DDocData);
  43.         Procedure Close; Override;
  44.  
  45.         Procedure Control    (whichControl:    ControlHandle;
  46.                               whichPart:        integer;
  47.                              where:            Point); Override;
  48.         Procedure MouseIn    (where:            Point;
  49.                              modifiers:        integer); Override;
  50.         Procedure TypeIn    (charCode:        SInt16); Override;
  51.         Procedure ExitCurField; Override;
  52.         Procedure DataChanged    (inDataID:    longint); Override;
  53.         Procedure Resize; Override;
  54.         Procedure Scroll    (newValue:        integer;
  55.                              oldValue:        integer); Override;
  56.  
  57.         Function  GetEngine: AMReminderEngine;
  58.  
  59. Procedure BuildRemindersList    (inControl:        ControlHandle);
  60. {$ifc false}
  61.         Procedure UpdateMenus; Override;
  62. {$endif}
  63.         Function  DoCommand        (inCommand:    longint): Boolean; Override;
  64.  
  65.         Procedure DoUndo;
  66.         Procedure DoCut;
  67.         Procedure DoCopy;
  68.         Procedure DoPaste;
  69.         Procedure DoClear;
  70.         Procedure DoSelectAll;
  71.         Procedure DoShowClipboard;
  72.  
  73.         Procedure DoAddReminder;
  74.         Procedure DoEditReminder;
  75.         Procedure DoDeleteReminder;
  76.     end;
  77.  
  78. {----------}
  79. Procedure CreateMainWindow    (inDoc:        AMReminderDoc;
  80.                              inData:    DDocData);
  81.  
  82. {----------}
  83. Implementation
  84.  
  85. Uses
  86.     Globals,
  87.     ResourceDefs,
  88.     DoScrap,
  89.     Scrolling,
  90.     ControlUtils,
  91.     Miscellany;
  92.  
  93. const
  94.     kLogoPicture        = 1;
  95.     kYearLabel        = 2;
  96.     kRemindersLabelLabel        = 3;
  97.     kRemindersList        = 4;
  98.     kAddButton        = 5;
  99.     kEditButton        = 6;
  100.     kDeleteButton        = 7;
  101.  
  102. {----------}
  103. Procedure CreateMainWindow (
  104.     inDoc:        AMReminderDoc;
  105.     inData:        DDocData);
  106. var
  107.     winObj:        MainWindow;
  108. begin
  109.     winObj := nil;
  110.     New (winObj);
  111.  
  112.     if winObj <> nil then begin
  113.         winObj.Initialize;
  114.         winObj.Open (inDoc, inData);
  115.     end;
  116. end;
  117.  
  118. {----------}
  119. Procedure MainWindow.Initialize;
  120. begin
  121.     Inherited Initialize;
  122. end;
  123.  
  124. {----------}
  125. Function  MainWindow.GetEngine: AMReminderEngine;
  126. begin
  127.     GetEngine := AMReminderEngine (mDoc.mEngine);
  128. end;
  129.  
  130. {----------}
  131. Procedure MainWindow.Open (
  132.     inDoc:        AMReminderDoc;
  133.     inData:        DDocData);
  134. var
  135.     window:        WindowPtr;
  136.     wftb:        Handle;
  137.     errCode:    OSErr;
  138. begin
  139.     mDoc := inDoc;
  140.     mData := inData;
  141.     mData.AddResponder (self);
  142.  
  143.     window := GetNewCWindow (WIND_MainWindow, nil, WindowPtr (-1));
  144.     if inDoc.mEngine.GetFilename <> '' then begin
  145.         SetWTitle (window, inDoc.mEngine.GetFilename);
  146.     end;
  147.     mWindow := window;
  148.     AMReminderDoc (mDoc).mMainWindowPtr := window;
  149.  
  150.     WindowPeek (window)^.windowKind := kAMWindowFlag;
  151.     SetWRefCon (window, ord4 (self));
  152.     SetPort (window);
  153.     SetInfo (window);
  154.  
  155.     wftb := GetResource ('Wftb', WIND_MainWindow);
  156.  
  157.     errCode := CreateRootControl (window, mRootControl);
  158.  
  159.     vScroll := nil;
  160.     hScroll := nil;
  161.  
  162.  
  163.     mLogoHandle := GetNewControl (CNTL_Logo, window);
  164.     SetWindowItemFont (mLogoHandle, wftb, 1);
  165.  
  166.     mYearLabel := GetNewControl (CNTL_Year, window);
  167.     SetWindowItemFont (mYearLabel, wftb, 2);
  168.     SetControlFromTEXT (mYearLabel, TEXT_Year);
  169.  
  170.     mRemindersLabelLabel := GetNewControl (CNTL_RemindersLabel, window);
  171.     SetWindowItemFont (mRemindersLabelLabel, wftb, 3);
  172.     SetControlFromTEXT (mRemindersLabelLabel, TEXT_RemindersLabel);
  173.  
  174.     mRemindersHandle := GetNewControl (CNTL_Reminders, window);
  175.     SetWindowItemFont (mRemindersHandle, wftb, 4);
  176.     BuildRemindersList (mRemindersHandle);
  177.     SetListBoxChoice (mRemindersHandle, mData.GetReminderChoice);
  178.  
  179.     mAddHandle := GetNewControl (CNTL_Add, window);
  180.     SetWindowItemFont (mAddHandle, wftb, 5);
  181.     SetDefaultState (mAddHandle, true);
  182.  
  183.     mEditHandle := GetNewControl (CNTL_Edit, window);
  184.     SetWindowItemFont (mEditHandle, wftb, 6);
  185.  
  186.     mDeleteHandle := GetNewControl (CNTL_Delete, window);
  187.     SetWindowItemFont (mDeleteHandle, wftb, 7);
  188.  
  189.     errCode := AdvanceKeyboardFocus (window);
  190.  
  191.     ShowWindow (window);
  192. end;
  193.  
  194. {----------}
  195. Procedure MainWindow.Close;
  196. begin
  197.     mData.RemoveResponder (self);
  198.  
  199.     AMReminderDoc (mDoc).mMainWindowPtr := nil;
  200.     SetInfo (nil);
  201.     HideWindow (mWindow);
  202.     DisposeWindow (mWindow);
  203.  
  204.     Dispose (self);
  205. end;
  206.  
  207. {----------}
  208. Procedure MainWindow.BuildRemindersList (
  209.     inControl:        ControlHandle);
  210. var
  211.     list:        ListHandle;
  212. begin
  213.     list := GetListHandle (inControl);
  214.     AddToList ("One",   list);
  215.     AddToList ("Two",   list);
  216.     AddToList ("Three", list);
  217.     AddToList ("Infinity",  list);
  218.  
  219. end;
  220.  
  221. {----------}
  222. Procedure MainWindow.Control (
  223.     whichControl:    ControlHandle;
  224.     whichPart:        integer;
  225.     where:            Point);
  226. var
  227.     bounds:            Rect;
  228.     newValue:        integer;
  229.     partcode:        SInt16;
  230. begin
  231.     ExitCurField ();
  232.  
  233.     if whichControl = mRemindersHandle then begin
  234.         if TrackClick (mRemindersHandle, where) then begin
  235.             mData.SetReminderChoice (GetListBoxChoice (mRemindersHandle));
  236.         end;
  237.     end;
  238.     if whichControl = mAddHandle then begin
  239.         if TrackClick (mAddHandle, where) then begin
  240.             DoAddReminder;
  241.         end;
  242.     end;
  243.     if whichControl = mEditHandle then begin
  244.         if TrackClick (mEditHandle, where) then begin
  245.             DoEditReminder;
  246.         end;
  247.     end;
  248.     if whichControl = mDeleteHandle then begin
  249.         if TrackClick (mDeleteHandle, where) then begin
  250.             DoDeleteReminder;
  251.         end;
  252.     end;
  253. end;
  254.  
  255. {----------}
  256. Procedure MainWindow.DataChanged (
  257.     inDataID:        longint);
  258. begin
  259. End;
  260.  
  261. {----------}
  262. Procedure MainWindow.MouseIn (
  263.     where:            Point;
  264.     modifiers:        integer);
  265. var
  266.     bounds:            Rect;
  267. begin
  268. end;
  269.  
  270. {----------}
  271. Procedure MainWindow.ExitCurField;
  272. var
  273.     errCode:    OSErr;
  274.     focus:        ControlHandle;
  275. begin
  276.     errCode := GetKeyboardFocus (mWindow, focus);
  277.  
  278.     if focus = nil then begin
  279.         { nothing to exit }
  280.  
  281.     end;
  282.     inherited ExitCurField;
  283. end;
  284.  
  285. {----------}
  286. Procedure MainWindow.TypeIn (
  287.     charCode:    SInt16);
  288. var
  289.     ch:            char;
  290.     errCode:    OSErr;
  291.     focus:        ControlHandle;
  292.     keyCode:    SInt16;
  293.     partcode:    SInt16;
  294. begin
  295.     errCode := GetKeyboardFocus (mWindow, focus);
  296.  
  297.     ch := chr (charCode);
  298.     if (ch = charEnter)
  299.     |  (ch = charReturn) then begin
  300.         ExitCurField;
  301.         SimulateClick (mAddHandle);
  302.         DoAddReminder;
  303.     end else if ch = charEsc then begin
  304.     end else if ch = charTab then begin
  305.         DoTab (BAnd (curEvent.modifiers, optionKey) <> 0);
  306.     end else if focus <> nil then begin
  307.         keyCode := BAnd (curEvent.message, keyCodeMask);
  308.         partcode := HandleControlKey (focus, keyCode, charCode, curEvent.modifiers);
  309.         mDoc.mEngine.SetDirty;
  310.     end else begin
  311.         SysBeep (1);
  312.     end;
  313. end;
  314.  
  315. {----------}
  316. Procedure MainWindow.Resize;
  317. begin
  318.     { application-specific code to resize items in window }
  319. end;
  320.  
  321. {----------}
  322. Procedure MainWindow.Scroll (
  323.     newValue:    integer;
  324.     oldValue:    integer);
  325. begin
  326.     { application-specific code to scroll window }
  327.     if gWhichScroll = vScroll then begin
  328.     end else begin    { horizontal }
  329.     end;
  330. end;
  331.  
  332. {----------}
  333. Procedure MainWindow.DoUndo;
  334. begin
  335. end; {DoUndo}
  336.  
  337. {----------}
  338. Procedure MainWindow.DoCut;
  339. var
  340.     curTE:        TEHandle;
  341. begin
  342.     curTE := GetCurTE ();
  343.  
  344.     if curTE <> nil then begin
  345.         TECut (curTE);
  346.         mDoc.mEngine.SetDirty;
  347.         scrapDirty := true;
  348.     end;
  349. end; {DoCut}
  350.  
  351. {----------}
  352. Procedure MainWindow.DoCopy;
  353. var
  354.     curTE:        TEHandle;
  355. begin
  356.     curTE := GetCurTE ();
  357.  
  358.     if curTE <> nil then begin
  359.         TECopy (curTE);
  360.         scrapDirty := true;
  361.     end;
  362. end; {DoCopy}
  363.  
  364. {----------}
  365. Procedure MainWindow.DoPaste;
  366. var
  367.     curTE:        TEHandle;
  368. begin
  369.     curTE := GetCurTE ();
  370.  
  371.     if curTE <> nil then begin
  372.         TEPaste (curTE);
  373.         mDoc.mEngine.SetDirty;
  374.     end;
  375. end; {DoPaste}
  376.  
  377. {----------}
  378. Procedure MainWindow.DoClear;
  379. var
  380.     curTE:        TEHandle;
  381. begin
  382.     curTE := GetCurTE ();
  383.  
  384.     if curTE <> nil then begin
  385.         TEDelete (curTE);
  386.         mDoc.mEngine.SetDirty;
  387.     end;
  388. end; {DoClear}
  389.  
  390. {----------}
  391. Procedure MainWindow.DoSelectAll;
  392. var
  393.     curTE:        TEHandle;
  394. begin
  395.     curTE := GetCurTE ();
  396.  
  397.     if curTE <> nil then begin
  398.         TESetSelect (0, 32767, curTE);
  399.     end;
  400. end; {DoSelectAll}
  401.  
  402. {----------}
  403. Procedure MainWindow.DoShowClipboard;
  404. begin
  405. end; {DoShowClipboard}
  406.  
  407. {----------}
  408. Procedure MainWindow.DoAddReminder;
  409. var
  410.     data:        DReminder;
  411. begin
  412.     data := NewDReminder;
  413.  
  414.     { add your code to set data fields }
  415.  
  416.     if GetAdd (data) then begin
  417.         { do something with data }
  418.     end;
  419.     Dispose (data);
  420. end;
  421.  
  422. {----------}
  423. Procedure MainWindow.DoEditReminder;
  424. var
  425.     data:        DReminder;
  426. begin
  427.     data := NewDReminder;
  428.  
  429.     { add your code to set data fields }
  430.  
  431.     if GetAdd (data) then begin
  432.         { do something with data }
  433.     end;
  434.     Dispose (data);
  435. end;
  436.  
  437. {----------}
  438. Procedure MainWindow.DoDeleteReminder;
  439. var
  440. begin
  441.     
  442. end;
  443.  
  444. {----------}
  445. Function MainWindow.DoCommand (
  446.     inCommand:        longint): Boolean;
  447. begin
  448.     DoCommand := true;
  449.     case inCommand of
  450.         cmdUndo:
  451.                 DoUndo;
  452.         cmdCut:
  453.                 DoCut;
  454.         cmdCopy:
  455.                 DoCopy;
  456.         cmdPaste:
  457.                 DoPaste;
  458.         cmdClear:
  459.                 DoClear;
  460.         cmdSelectAll:
  461.                 DoSelectAll;
  462.         cmdShowClipboard:
  463.                 DoShowClipboard;
  464.         cmdAddReminder:
  465.                 DoAddReminder;
  466.         cmdEditReminder:
  467.                 DoEditReminder;
  468.         cmdDeleteReminder:
  469.                 DoDeleteReminder;
  470.  
  471.         otherwise
  472.                 DoCommand := false;
  473.     end; {case}
  474. end;
  475.  
  476. end.
  477.